package com.biscuit.page.basicservice.remote.api;

import com.biscuit.page.basicservice.api.IAuthorizationRemote;
import com.biscuit.common.base.BaseResponse;
import com.biscuit.common.base.BaseResponseVoid;
import com.biscuit.page.basicservice.api.model.request.authorization.AuthorizationAReq;
import com.biscuit.page.basicservice.api.model.request.authorization.AuthorizationGetVerifyCodeAReq;
import com.biscuit.page.basicservice.api.model.response.authorization.AuthorizationAResp;
import com.biscuit.page.basicservice.api.model.response.authorization.AuthorizationEncryptAResp;
import com.biscuit.page.basicservice.api.model.response.user.UserInfoAResp;
import com.biscuit.page.basicservice.service.AuthorizationService;
import com.biscuit.page.basicservice.utils.BaseResponseUtil;
import com.biscuit.page.basicservice.utils.MD5Util;
import com.biscuit.page.basicservice.utils.SecurityUtil;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author mazihao
 * @createTime 2024/3/22 18:21
 */
@RestController
public class IAuthorizationRemoteImpl implements IAuthorizationRemote {

    @Resource
    private AuthorizationService authorizationService;

    @Override
    public BaseResponse<AuthorizationAResp> authentication(AuthorizationAReq req) {
        return this.authorizationService.login(req);
    }

    @Override
    public BaseResponse<BaseResponseVoid> getVerifyCode(AuthorizationGetVerifyCodeAReq req) {
        return this.authorizationService.getVerifyCode(req);
    }

    @Override
    public BaseResponse<AuthorizationEncryptAResp> encryptMd5(String text) {
        AuthorizationEncryptAResp response = new AuthorizationEncryptAResp();
        response.setText(MD5Util.md5(text));
        return BaseResponseUtil.success(response);
    }

    @Override
    public BaseResponse<AuthorizationEncryptAResp> encryptUnsymmetrical(String text) {
        AuthorizationEncryptAResp response = new AuthorizationEncryptAResp();
        response.setText(SecurityUtil.encrypt(text));
        return BaseResponseUtil.success(response);
    }

    @Override
    public BaseResponse<BaseResponseVoid> logout() {
        return this.authorizationService.logout();
    }

    @Override
    public BaseResponse<UserInfoAResp> getUserInfoByCurrentLogin() {
        return BaseResponseUtil.success(this.authorizationService.getUserInfoByCurrentLogin());
    }

}
